package com.server.test.servlet.console;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.arnx.jsonic.JSON;

import com.server.test.command.request.ReservationRequestBean;
import com.server.test.command.response.ReservationResponseBean;

public class LoginServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		
//		request.getRequestDispatcher("/zhaowei_server/console/yuyue/yueyue.jsp").forward(request, response);
		
		PrintWriter out = response.getWriter();
		out.write("你好");
		out.flush();
		out.close();
		
	}
	
	
	@Override
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		// 处理中文问题
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		String jsonStrRequest = readJsonFromRequestBody(request);
		System.out.println("请求的json数据 ： " + jsonStrRequest);
		PrintWriter out = response.getWriter();
		out.write("你好");
		out.flush();
		out.close();

	}

	private String readJsonFromRequestBody(HttpServletRequest request)
			throws IOException {
		StringBuffer jsonBuf = new StringBuffer();
		char[] buf = new char[2048];
		int len = -1;
		BufferedReader reader = request.getReader();
		while ((len = reader.read(buf)) != -1) {
			jsonBuf.append(new String(buf, 0, len));
		}
		return jsonBuf.toString();
	}

}
